package com.example.mytitle;

import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;


public class TitleLayout extends LinearLayout{
    public TitleLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.title,this);

        //这是自定义标题控件的按钮点击事件
        Button titleBack = findViewById(R.id.title_back);
        Button titleMenu = findViewById(R.id.title_menu);
        TextView titleText = findViewById(R.id.title_text);

        titleBack.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ((Activity)getContext()).finish();
            }
        });

        titleMenu.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getContext(), "menu", Toast.LENGTH_SHORT).show();
            }
        });
    }
}
